package org.mlz.game.business

import com.sun.javafx.scene.traversal.Direction
import org.mlz.game.Config
import org.mlz.game.model.View

/**
 *<p>
 *移动运动的能力
 *</p>
 * CreateBy  Malingzhao
 * @date  2020/9/18
 */

interface Movable:View {


    val speed:Int
    /**
     * 可移动的物体存在方向
     */
    val currentDirection:Direction
    /**
     * 判断移动五i是否和阻塞物体发生碰撞
     *@return 碰撞  要碰撞的方向
     */
    fun willCollision(block: Blockable): Direction? {
        //将要碰撞的时候做判断

        //未来的坐标
        var x = this.x
        var y = this.y

        //将要碰撞的时候做判断
        when (currentDirection) {
            Direction.UP -> y -= speed
            Direction.DOWN -> y += speed
            Direction.LEFT -> x -= speed
            Direction.RIGHT -> x += speed

        }



        //边界进行检测
        if (x < 0)  return Direction.LEFT;
        if (x > Config.gameWidth - width) return Direction.RIGHT;
        if (y < 0) return Direction.UP;
        if (y > Config.gameHeight - height)return Direction.DOWN;



        var collission = checkCollision(block.x, block.y, block.width, block.height, x, y, width, height)
        return if (collission) currentDirection else null
    }


    //通知碰撞
    //发现碰不上
    fun notifyCollisionBlock(direction: Direction?, block: Blockable?)
}
